package com.fengpanlong.service;


import com.fengpanlong.dao.EmployeeDao;
import com.fengpanlong.entity.Employee;
import com.fengpanlong.util.StringUtil;
import com.fengpanlong.util.exception.ServiceException;

public class Validate {
	public static Employee userIsOK(String username, String password) throws ServiceException{
		if(StringUtil.isEmpty(username) || StringUtil.isEmpty(password)) {
			throw new ServiceException("用户名或密码不能为空！");
		} else {
			EmployeeDao ed = new EmployeeDao();
			Employee employee = ed.findByName(username);
			if(employee != null) {
				if(password.equals(employee.getPassword())) {
					return employee;
				} else {
					throw new ServiceException("用户名或密码不正确！");
				}
			} else {
				throw new ServiceException("用户名或密码不正确！");
			}
		}
	}
}
